package com.rocket.controller;

import com.rocket.param.TeduClass;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TalkController {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @GetMapping("/talk")
    public String talk(){
        String txt = "你好啊！";
        Message<String> message = MessageBuilder.withPayload(txt).build();
        rocketMQTemplate.asyncSend("topicA", message, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                System.out.println("消息发送成功");
            }

            @Override
            public void onException(Throwable throwable) {
                System.out.println("消息发送失败");
            }
        });
        return "已开始对话";
    }
}
